[codex] Structure GitLab CLI failures#3458
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
1547139 to
fcc01bc
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Not-found always MR error
- Changed fromVcsError to map not-found to generic GitLabCliCommandError, and added a refineNotFoundToMrError helper applied only in getMergeRequest and checkoutMergeRequest to correctly produce GitLabMergeRequestNotFoundError only for MR operations.
Or push these changes by commenting:
@cursor push 9529c4928a
Preview (9529c4928a)
diff --git a/apps/server/src/sourceControl/GitLabCli.ts b/apps/server/src/sourceControl/GitLabCli.ts
--- a/apps/server/src/sourceControl/GitLabCli.ts
+++ b/apps/server/src/sourceControl/GitLabCli.ts
@@ -101,7 +101,6 @@
case "authentication":
return new GitLabCliAuthenticationError({ ...context, cause });
case "not-found":
- return new GitLabMergeRequestNotFoundError({ ...context, cause });
case "command-failed":
case undefined:
return new GitLabCliCommandError({ ...context, cause });
@@ -315,6 +314,24 @@
}
}
+function refineNotFoundToMrError(error: GitLabCliError): GitLabCliError {
+ if (
+ error._tag === "GitLabCliCommandError" &&
+ error.cause != null &&
+ typeof error.cause === "object" &&
+ "failureKind" in error.cause &&
+ error.cause.failureKind === "not-found"
+ ) {
+ return new GitLabMergeRequestNotFoundError({
+ operation: error.operation,
+ command: error.command,
+ cwd: error.cwd,
+ cause: error.cause,
+ });
+ }
+ return error;
+}
+
function normalizeHeadSelector(headSelector: string): string {
const trimmed = headSelector.trim();
const ownerBranch = /^[^:]+:(.+)$/.exec(trimmed);
@@ -424,6 +441,7 @@
cwd: input.cwd,
args: ["mr", "view", input.reference, "--output", "json"],
}).pipe(
+ Effect.mapError(refineNotFoundToMrError),
Effect.map((result) => result.stdout.trim()),
Effect.flatMap((raw) =>
Effect.sync(() => decodeGitLabMergeRequestJson(raw)).pipe(
@@ -578,7 +596,7 @@
execute({
cwd: input.cwd,
args: ["mr", "checkout", input.reference],
- }).pipe(Effect.asVoid),
+ }).pipe(Effect.mapError(refineNotFoundToMrError), Effect.asVoid),
});
});You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit fcc01bc. Configure here.
ApprovabilityVerdict: Approved This PR refactors GitLab CLI error handling by splitting a single generic error class into multiple specific typed error classes with structured tag-based matching instead of string-based detection. The changes are internal infrastructure improvements with comprehensive test coverage and no impact on core business logic. You can customize Macroscope's approvability policy. Learn more. |
fcc01bc to
b61c656
Compare
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
b61c656 to
8b7ee6d
Compare


Summary
Validation
vp test apps/server/src/sourceControl/GitLabCli.test.ts apps/server/src/sourceControl/GitLabSourceControlProvider.test.tsvp checkvp run typecheckNote
Medium Risk
Changes how all GitLab CLI failures are typed and surfaced; callers matching on the old single error shape or detail strings need updates, though behavior is covered by updated tests.
Overview
Replaces the single free-form
GitLabCliErrorwith tagged Schema error classes (unavailable, authentication, MR not found, generic command failure, and operation-specific decode errors) plus aGitLabCliErrorunion andisGitLabCliError.Process failures are classified via
VcsErrortags andfailureKind(Match.valueTags) instead of parsing stderr/detail strings; spawn → unavailable, auth →GitLabCliAuthenticationError, etc.MR-specific paths (
getMergeRequest,checkoutMergeRequest) useexecuteMergeRequestsonot-foundbecomesGitLabMergeRequestNotFoundErrorwith the MR reference in the message; other APIs (e.g. project 404) stayGitLabCliCommandError.JSON decode failures now map to dedicated decode error types with structured
cause; user-facingmessage/detailno longer leak raw upstream text.Reviewed by Cursor Bugbot for commit 8b7ee6d. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Structure GitLab CLI failures into typed error classes
GitLabCliErrorclass with a union of specific typed errors:GitLabCliUnavailableError,GitLabCliAuthenticationError,GitLabMergeRequestNotFoundError,GitLabCliCommandError, and operation-specific decode errors.getMergeRequest,checkoutMergeRequest) now throwGitLabMergeRequestNotFoundErrorwith a reference-specific message (e.g. "Merge request 4888 was not found") instead of a generic error.GitLabClimethod maps decode failures to a dedicated error class (e.g.GitLabRepositoryDecodeError,GitLabNamespaceDecodeError) rather than a shared generic decode error.errorText) to structuredVcsErrortag/failureKindmatching via staticfromVcsErrormethods.GitLabCliErrormust update to use the newisGitLabCliErrorguard or handle individual error variants.Macroscope summarized 8b7ee6d.